package com.gitee.ixtf.cqrs.kotlinx

import com.gitee.ixtf.cqrs.client.EventSourcedEntityClient
import com.gitee.ixtf.cqrs.client.KeyValueEntityClient
import com.gitee.ixtf.cqrs.internal.EventSourcedEntityClientImpl
import com.gitee.ixtf.cqrs.internal.KeyValueEntityClientImpl
import io.vertx.core.Vertx

internal const val ENTITY_ID_KEY = "ENTITY_ID_KEY"
internal const val EB_ADDRESS_EVENT_SOURCED_ENTITY_CONSUMER =
    "__eb:ComponentConsumer:EventSourcedEntity__"

data class ComponentConsumerMessage<S, E>(
    val previous: S,
    val events: List<E>,
    val current: S,
)

fun Vertx.forEventSourcedEntity(entityId: String): EventSourcedEntityClient =
    EventSourcedEntityClientImpl(this, entityId)

fun Vertx.forKeyValueEntity(entityId: String): KeyValueEntityClient =
    KeyValueEntityClientImpl(this, entityId)
